In [1]:
%run startup.py
In [2]:
%%javascript
$.getScript('./assets/js/ipython_notebook_toc.js')
source: http://reactivex.io/documentation/operators.html#tree.
(transcribed to RxPY 1.5.7, Py2.7 / 2016-12, Gunther Klessinger, axiros)
This tree can help you find the ReactiveX Observable operator you’re looking for.
See Part 1 for Usage and Output Instructions.
We also require acquaintance with the marble diagrams feature of RxPy.
In [1]:
reset_start_time(O.filter) # alias: where
d = subs(O.range(0, 5).filter(lambda x, i: x % 2 == 0))
In [3]:
reset_start_time(O.slice)
s = marble_stream('r-e-a-c-t-i-v-e-|')
d = subs(s.slice(5, 10))
sleep(1)
# start stop step:
d = subs(s.slice(1, -1, 2))
In [27]:
rst(O.first)
# match on index:
d = subs(O.from_((1, 2 ,3)).first(lambda x, i: i==1))
In [28]:
rst(O.take)
d = subs(O.from_((1, 2, 3, 4)).take(2))
rst(O.take_with_time)
d = subs(marble_stream('1-2-3-4|').take_with_time(200))
In [29]:
rst(O.last, title=True)
d = subs(O.from_((1, 2, 3)).last(lambda x: x < 3))
rst(O.last_or_default, title=True)
d = subs(O.from_((1, 2, 3)).last_or_default(lambda x: x > 3))
d = subs(O.from_((1, 2, 3)).last_or_default(lambda x: x > 3, '42'))
rst(O.take_last, title=True)
d = subs(O.from_((1, 2, 3, 4)).take_last(2))
In [30]:
rst(O.element_at)
d = subs(O.from_((1, 2, 3, 4)).element_at(2))
rst(O.element_at_or_default)
d = subs(O.from_((1, 2, 3, 4)).element_at_or_default(6, '42'))
In [31]:
rst(O.skip, title=True)
d = subs(O.range(0, 5).skip(2))
rst(O.skip_with_time, title=True)
d = subs(marble_stream('1-2-3-4-5-6').skip_with_time(200))
In [16]:
rst(O.skip_while)
# skipping only AS LONG AS the function is true. If already false at the beginning -> all flushed:
d = subs(O.from_((1, 2, 3, 4, 5, 6)).skip_while(lambda x: x in (1, 2)))
In [3]:
rst(O.skip_until)
s1 = marble_stream('1-2-3-4-5|')
s2 = marble_stream('--2------|')
d = subs(s1.skip_until(s2))
sleep(0.5)
rst(O.skip_until_with_time)
d = subs(s1.skip_until_with_time(300))
In [3]:
rst(O.skip_last)
s1 = marble_stream('1-2-3-4-5|')
s2 = marble_stream('--2------|')
d = subs(s1.skip_last(2))
sleep(0.5)
rst(O.skip_last_with_time)
d = subs(s1.skip_last_with_time(300))
In [6]:
rst(O.take_while)
d = subs(O.from_((1, 2, 3)).take_while(lambda x: x<3))
In [8]:
# (see above)
In [12]:
rst(O.take_until)
s1 = marble_stream('1-2-3-4-5|')
s2 = marble_stream('--2------|')
d = subs(s1.take_until(s2))
sleep(0.5)
rst(O.take_until_with_time)
d = subs(s1.take_until_with_time(300))
In [26]:
rst(O.sample)
xs = marble_stream('1-2-3-4-5-6-7-8-9-1-2-3-4-5-6-E|')
sampler =marble_stream('---1---1----------1------------|')
d = subs(xs.sample(300))
sleep(2)
d = subs(xs.sample(sampler=sampler))
In [30]:
rst(O.debounce)
s = marble_stream('-12-3-4--5--6---7---8----9----a')
print('flushing a value every >= 300ms')
d = subs(s.debounce(300))
In [43]:
rst(O.distinct)
s = O.from_((1, 2, 1, 1, 3))
d = subs(s.distinct(lambda x: x*2))
d = subs(s.distinct(lambda x: x, lambda a, b: a==2))
In [45]:
rst(O.distinct_until_changed)
s = O.from_((1, 2, 1, 1, 3))
d = subs(s.distinct_until_changed(lambda x: x*2))
d = subs(s.distinct_until_changed(lambda x: x, lambda a, b: a==2))
In [10]:
rst(O.delay)
header("note the absolute time of emissions:")
d = subs(O.range(0, 10).delay(1000))
In [18]:
rst(O.amb)
s1 = O.range(0, 5).delay(100)
s2 = O.range(10, 5)
d = subs(O.amb(s1, s2))
In [ ]: